package com.pcbly.web.components.utils.template.pagemess;

import java.io.File;
import java.lang.reflect.Field;
 
import com.pcbly.web.bean.crm.CxdBean; 
import com.pcbly.web.components.utils.ClassUtilsStatic;
import com.pcbly.web.components.utils.template.TemplateModel;
 
public class ModelPageAndMessages extends IModelPageAndMessage {
	
	public void execute(Class<?> clz) {
		try {
			String pachageString = clz.getPackage().getName();
			String path = pachageString.replaceAll("\\.", "/");
			String pacha = clz.getPackage().getName();
			File file = new File("src/" + path);
			if (file.isDirectory()) {
				String[] files = file.list();
				for (String fi : files) {
					if (fi.indexOf("java") >= 0) {
						String te = fi.substring(0, fi.indexOf("."));
						te = pacha + "." + te;
						Class<?> temp = ClassUtilsStatic.forName(te);

						TemplateModel model = new TemplateModel();
						model.setClz(temp);
						model.setClzName(temp.getName());

						Field[] fields = temp.getDeclaredFields();
						Field[] tempFields = new Field[fields.length - 1];
						int i = 0;
						for (Field field : fields) {
							if (!(field.getName().equals("serialVersionUID")
									|| field.getName().equals("endDate") || field
									.getName().equals("startDate"))) {
								tempFields[i] = field;
								i++;
							}
						}
						execute(model, tempFields);
						// break;
					}
				}
			}
		} catch (Exception e) {

		}
	}

	public static void main(String[] args) {
		System.out.println("Begin...................");
		ModelPageAndMessages model = new ModelPageAndMessages();
		model.execute(CxdBean.class);
		System.out.println("End...................");
	}
}
